package scr 
{
	import data.XMLConfig;
	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import ru.gosoplata.model.TmpModel;
	import ru.gosoplata.view.FooterView;
	import uicontrols.ButtonBase;
	import usr.ServiseData;
	/**
	 * ...
	 * @author a.orleansky
	 */
	public class ScreenInfo extends ScreenBase implements IScreen 
	{
		public	var btn_next:ButtonBase = new ButtonBase("next", 0x00FF00);
		public var btn_terminal:ButtonBase = new ButtonBase("but_terminal", 0x555555,TmpModel.IMG_FOLDER+"/dog_oferti/images/icon_o_terminale.png");
		public var btn_oferta:ButtonBase = new ButtonBase("but_oferta", 0x555555,TmpModel.IMG_FOLDER+"/dog_oferti/images/icon_oferta.png");
		public var btn_service:ButtonBase = new ButtonBase("wcservice",0x555555);
		private var pic_count:Number=0;
		private var header:TextField = new TextField();
		private var info_txt:TextField = new TextField();
		private var info_data_txt:TextField = new TextField();
		
		private var _footer:FooterView = new FooterView();
		
		public function ScreenInfo()
		{
			super("info");
		}
		
		override protected function init(e:Event):void 
		{
			super.init(e);
			
			addChild(_footer);
			
			addChild(btn_service);
			
			btn_terminal.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_terminal.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			addChild(btn_terminal);
			pic_count++
			
			btn_oferta.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_oferta.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			addChild(btn_oferta);
			pic_count++
			
			btn_next.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_next.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			btn_next.visible = false;
			addChild(btn_next);
			pic_count++;
			
			btn_service.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			//loadBanner(TmpModel.IMG_FOLDER+"/sotovie_operatori/images/reklama_title.png");
		}	
		
		override public function reDraw():void
		{
			_footer.reDraw();
			
			var text_fmt:TextFormat = TmpModel.getTextFormat(32, 0x676767,true);
			text_fmt.letterSpacing = 7;
			//TODO: PROFILE определение сортира или нет профайла по ServiseData.READY (есть ли в конфиге нод про сортирных техников). костыль. Клименко отказыватся делать нормальное определение.
			if (!ServiseData.READY) btn_service.visible = false;
			TmpModel.debugOutput.add('******************** ' + ServiseData.READY + " * " + btn_service.visible + " ********************");
			header.embedFonts = true;
			header.width = 400;
			header.defaultTextFormat = text_fmt;
			header.antiAliasType = AntiAliasType.ADVANCED;
			header.thickness = -50;
			header.multiline = false;
			header.text = "О терминале";
			header.autoSize = TextFieldAutoSize.CENTER;
			header.y = 320
			header.x = stage.stageWidth/2 - header.width/2;
			addChild(header);
			btn_terminal.fixDownBtn();

			var info_fmt:TextFormat = TmpModel.getTextFormat(18, 0x676767,true);
			info_fmt.letterSpacing = 2;
			info_fmt.leading = 10;
			
			info_txt.embedFonts = true;
			info_txt.width = 350;
			info_txt.height = 500;
			info_txt.defaultTextFormat = info_fmt;
			info_txt.antiAliasType = AntiAliasType.ADVANCED;
			info_txt.thickness = -50;
			info_txt.multiline = true;
			info_txt.y = 410
			info_txt.x = 50;
			info_txt.selectable = false;
			addChild(info_txt);
			info_data_txt.embedFonts = true;
			info_data_txt.width = 750;
			info_data_txt.height = 550;
			info_data_txt.defaultTextFormat = info_fmt;
			info_data_txt.antiAliasType = AntiAliasType.ADVANCED;
			info_data_txt.thickness = -50;
			info_data_txt.multiline = true;
			info_data_txt.autoSize = TextFieldAutoSize.LEFT;
			info_data_txt.y = 410;
			info_data_txt.x = info_txt.x + info_txt.width+10;
			info_data_txt.selectable = false;
			addChild(info_data_txt);
			
			//var terminalid:String = XMLConfig.getTerminalCODE();
			info_txt.htmlText = "<P ALIGN='RIGHT'><font color='#1E5ADC'>Номер терминала : </font>\n" +
								"<font color='#1E5ADC'>Адрес : </font>\n"+
								"<font color='#1E5ADC'>Наименование исполнителя : </font>\n"+
								"<font color='#1E5ADC'>ИНН исполнителя : </font>\n"+
								"<font color='#1E5ADC'>Адрес исполнителя : </font>\n"+
								"<font color='#1E5ADC'>Контактный телефон : </font></P>";
			info_data_txt.htmlText =XMLConfig.getTerminalCODE() + "\n" +
								XMLConfig.getTerminalAdress()+ "\n"+
								XMLConfig.getPOName()+ "\n"+
								XMLConfig.getPOinn()+ "\n"+
								XMLConfig.getPOadress()+ "\n"+
								XMLConfig.getPhone();
		}
		
		private function allPicLoaded(e:Event):void 
		{
			pic_count--;
			if (pic_count == 0) 
			{
				btn_next.x = stage.stageWidth - (btn_next.width + 20)
				btn_next.y = stage.stageHeight - (btn_next.height + 20);
				
				btn_oferta.y = btn_terminal.y = 190;
				btn_terminal.x = 50;
				btn_oferta.x = stage.stageWidth - 50 - btn_oferta.width;
				
				btn_service.x = stage.stageWidth - 120 - 20;
				btn_service.y = stage.stageHeight - 120 - 20;
			}
		}	
		
		private function pressBtn(e:Event):void 
		{
			switch(e.target.name) 
			{
				case "but_oferta":
					TmpModel.tmpGlobalController.onClick("oferta");
					break;
				case "wcservice":
					TmpModel.tmpGlobalController.onClick("wcservice");
					break;
			}
		}
	}
}